/**
 * Created by lvzj on 15/10/14.
 */

var specialty = "";

$('.apply').css({'position':'absolute','top':$(window).height()-$('.apply').outerHeight()});

$('.checkbox').each(function(){
    $(this).click(function(){
        if($(this).parent('li').hasClass('cur')==false){
            $(this).after('<img src="'+resUrl+'images/leifeng/cur.png" class="icon">');
            $(this).parent('li').addClass('cur');
            specialty += ","+$(this).val();
        }else{
            $(this).siblings('.icon').hide();
            $(this).parent('li').removeClass('cur');
            specialty = specialty.replace(","+$(this).val(),"");
        }
    });
});

function apply(){
    var realName = $('#realName').val();
    var phone = $('#phone').val();
    var address = $('#address').val();
    if(!realName){
        $('.loading').show();
        $('.loading-con').html('请输入姓名');
        setTimeout(function () {
            $('.loading').hide();
        }, 1000);
        return ;
    }
    if(!phone){
        $('.loading').show();
        $('.loading-con').html('请输入手机号');
        setTimeout(function () {
            $('.loading').hide();
        }, 1000);
        return ;
    }
    if(!address){
        $('.loading').show();
        $('.loading-con').html('请输入地址');
        setTimeout(function () {
            $('.loading').hide();
        }, 1000);
        return ;
    }
    $('#queryApply').show();
    $.ajax({
        type: "POST",
        url: serverUrl+'/rest/v1.0/app/userRole/apply/' + params.token + '/' + params.deviceId,
        data: {type:2,name:realName,phone:phone,address:address,specialty:specialty.substring(1)},
        dataType: "json",
        success: function(data){
            setTimeout(function () {
                $('#queryApply').hide();
                var type = params.type;
                if (type == 'ios') {
                    document.location.href = "66xiaoqu:closeWebView";
                } else {
                    webviewhandle.finish();//webviewhandle为webview注册对象
                }
            }, 2000);
        }
    });
}